<?php


namespace app\home\controller;


use app\common\controller\BaseController;
use app\home\model\Task as model;
use think\App;

class Task extends BaseController
{
    protected $model;

    public function __construct(App $app, model $model)
    {
        parent::__construct($app);
        $this->model = $model;
    }

    /**
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     */
    public function query()
    {
        $where = [];
        $where['status'] = 1;
        $where['deleted'] = 0;
        $order = ['create_time' => 'desc'];
        $category = input('category/d', 0);
        !empty($category) && $where['category'] = $category;
        $field = "id,title,id task_start,category,category category_name,id task_status,num,price,step,create_time,startTime,endTime";
        $page = input('page/d', 1);
        $pageSize = input('page_size/d', 10);
        return $this->model->getList($where, $field, $order, $page, $pageSize);
    }

    /**
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\DataNotFoundException
     */
    public function read()
    {
        return $this->model->getOne($this->params);
    }
}